<?php
class LatqsController extends AppController {

	var $name = 'Latqs';

	function index() {
		$this->Latq->recursive = 0;
		$this->set('latqs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid latq', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('latq', $this->Latq->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Latq->create();
			if ($this->Latq->save($this->data)) {
				$this->Session->setFlash(__('The latq has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The latq could not be saved. Please, try again.', true));
			}
		}
		$this->Latq->Mon->displayField='mamom';
		$mons = $this->Latq->Mon->find('list');
		//debug($mons);
		$this->set(compact('mons','latqs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid latq', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Latq->save($this->data)) {
				$this->Session->setFlash(__('The latq has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The latq could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Latq->read(null, $id);
		}
		$mons = $this->Latq->Mon->find('list');
		$this->set(compact('mons'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for latq', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Latq->delete($id)) {
			$this->Session->setFlash(__('Latq deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Latq was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
